import lejos.nxt.LCD;
import lejos.nxt.Motor;
import lejos.nxt.NXTRegulatedMotor;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;

public class Sonar
{
    private static UltrasonicSensor s = new UltrasonicSensor(SensorPort.S4);
    private static NXTRegulatedMotor m = Motor.C;
    
    private Sonar () 
    {
    	
    }
    
    public static void lookLeft ()
    {
        if (m.getPosition() < 90)
            m.rotateTo(90);
    }
    
    public static void lookRight ()
    {
        if (m.getPosition() > -90)
            m.rotateTo(-90);
    }
    
    public static void lookAhead ()
    {
        if (m.getPosition() != 0)
            m.rotateTo(0);
    }
    
    public static int getDistance ()
    {
        return s.getDistance();
    }
    
    public static void printDistance (byte x, byte y)
    {
        LCD.drawString("   "+s.getDistance() + "   ",x,y);
    }
}
